<?php

/**
 * mydoor actions.
 *
 * @package    nfzz
 * @subpackage mydoor
 * @author     Antonio J. Balmón
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class mydoorActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
	$comments_list = Array();
  	$username = $this->getUser()->getGuardUser()->getUsername();

  	$query = Doctrine_Query::create()
	  	->select("u.first_name, u.last_name, u.gender, u.photo, u.interests, g.country")
	  	->from("SfGuardUser u")
	  	->leftJoin("u.GeoLocation g")
	  	->where("u.username = ?", $username);
  	$userinfo = $query -> fetchOne();
  	$this->userinfo = $userinfo;
  	
  	$nearnews_list = Doctrine_Core::getTable('nfNearnews')->getNews($username);
  	foreach($nearnews_list as $item=>$value) {
  		$comments_list[$value["id"]] = Doctrine_Core::getTable('NfNearnewComment')->getComments($value["id"]);
  	}
  	
  	$this->form = new NfNearnewsForm();
  	$this->nearnews_list = $nearnews_list;
  	$this->comments_list = $comments_list;
  }
  
  public function executeSave(sfWebRequest $request)
  {
    $form = new NfNearnewsForm();
 
    if ($request->isMethod('post'))
    {
		$this->processForm($request, $form);
    }

	/*
    if (!$this->getUser()->isAuthenticated())
    {
      $this->getUser()->setFlash('notice', 'You are not signed in!');
      $this->redirect('@home');
    }

    $form = new NfNearnewsForm();

    if ($request->isMethod('post'))
    {
      $user = $this->processForm($request, $form);
      $this->redirect('@mydoor');
    }
    */
  }

  protected function processForm(sfWebRequest $request, NfNearnewsForm $form)
  {
    $form->bind($request->getPostParameters());
    //echo $request->getParameter("whatareyoudoing");
    //return $this->renderText("success");
    if ($form->isValid())
    {
      //$user = $form->save();
      //return $user;
    }
  }
}

